package com.youth.mq.producer;

import com.youth.utils.CodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName AckProducer
 * @Description: TODO 如果消费端设置手动ack，那么生产端发送消息一定发送CorrelationData，并且全局唯一，用于唯一标识消息。
 * @Author yjwu
 * @Date 2020/1/6 14:17
 **/
@Component
@Slf4j
public class RMQProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(String message, String exchange, String routingKey) {
        //添加唯一id
        CorrelationData correlationData = new CorrelationData(CodeUtil.getUUIDCode());
        log.info("message:{}", message);
        log.info("callbackSender UUID:{} ", correlationData.getId());
        this.rabbitTemplate.convertAndSend(exchange, routingKey, message, correlationData);
    }

}
